package model
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import view.Details;
	
	//碰撞检测部分
	public class HitTestMonster extends Sprite
	{
		private var s1:MovieClip = new MovieClip;
		private var s2:MovieClip = new MovieClip;

		private var radius2:Number;

		private var radius1:Number;
		//private var d:Details = new Details();
		public function HitTestMonster(a2:MovieClip)
		{
			super();
			s2 = a2;
			//s1 = a1;
			//此处全部为可以替换的部分
			s1.graphics.beginFill(0xff0000);
			radius1 = 50;
			s1.graphics.drawCircle(0,0,radius1);
			s1.graphics.endFill();
			addChild(s1);
			s1.alpha = 0.5;
			s1.x = s1.y = 200;
			
			radius2 = 10;
			/*s2.graphics.beginFill(0x00ff00);
			
			s2.graphics.drawCircle(0,0,radius2);
			s2.graphics.endFill();
			addChild(s2);
			s2.x = s2.y = 30;*/
			s1.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown1);
			s2.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown2);
			addEventListener(Event.ENTER_FRAME,onEnterFrame);
		}
		
		protected function onMouseDown1(event:MouseEvent):void
		{
			s1.startDrag();
			stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
		}
		
		//碰撞检测的内容
		public function onEnterFrame(event:Event):void
		{
			if(Math.sqrt((s1.x-s2.x)*(s1.x-s2.x)+(s1.y-s2.y)*(s1.y-s2.y)) < radius1 + radius2){
				//trace("hit you");
				s2.blood = s2.blood - .5;
				trace(s2.blood);
			}
		}
		
		protected function onMouseDown2(event:MouseEvent):void
		{
			s2.startDrag();
			stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
		}
		
		protected function onMouseUp(event:MouseEvent):void
		{
			s2.stopDrag();
			s1.stopDrag();
		}
	}
}